//绘制纵向柱形图
function DRAWPRTAITCHART(url,modelSend,drawContainer) {
    this.draw = function () {
        console.log(modelSend);
        $.ajax({ type: "post",
            url: url,
            dataType: "json",
            data:{"paramData":JSON.stringify(modelSend)},
            success: function (result) {
                console.log(result);
                var dpInstance= new DRAWPRTAIT(result,drawContainer);
                dpInstance.draw(result,drawContainer);
            },
            error: function (err) {
                console.log("服务器链接失败");
            }});
    };
}
function DRAWPRTAIT(json,drawContainer){
    this.colorg=['#357FB7','#D95550','#9AC062'];
    //根据得到的数据绘制Y轴
    this.setYaxis=function(data){
        var yaxArray=[];
        for(var i=0;i<data.axis.yCnt;i++){
            var k=i;
            var obj={labels:{
                    formatter:function(){
                        return Highcharts.numberFormat(this.value,0,".",",");
                    },
                    style:{color:''}},
                title:{text:''}};
            obj.labels.style.color =data.data[k]? this.colorg[data.data[k].yAxis]:"none";
            if(data.theme.yAxis[k].align=='right'||data.theme.yAxis[k].opposite=='false'){
                obj.labels.formatter=function(){
                    return Highcharts.numberFormat(this.value,0,".",",")+"%";
                };
                obj.opposite='true';
                obj.minPadding="0";
                obj.startOnTick="false";
            }
            yaxArray.push(obj);
        }
        return yaxArray;
    };
    //根据得到的数据设置指标
    this.setSeries=function(dataSource){
        var serArray=[];
        for(var key in dataSource.data){
            var obj={};
            var num=dataSource.data[key].yAxis;
            // console.log(num);
            obj.name=dataSource.data[key].label;
            obj.type=dataSource.theme.yAxis[num].type;
            obj.yAxis=dataSource.data[key].yAxis;
            obj.data=dataSource.data[key].value;
            obj.color=this.colorg[key];
            obj.zIndex=dataSource.theme.yAxis[num].type=='line'?1:0;
            obj.dataLabels={
                enabled: true,
                formatter:function(){
                    if(this.series.name.match(/(.*?比)/)){
                        return Highcharts.numberFormat(this.y,0,".",",")+'%';
                    }
                    else{
                        return Highcharts.numberFormat(this.y,0,".",",");
                    }
                },
                color: this.colorg[key]
            };
            serArray.push(obj);
        }
        return serArray;
    };
    //绘制纵向坐标轴的方法
    this.draw=function(json,container){
        var option={
            xAxis: [{
                categories:json.axis.x,
                crosshair: true

            }],
            yAxis:this.setYaxis(json),
            tooltip: {
                shared: true,
                useHTML:true,
                pointFormatter:function(){
                    if(this.series.name.match(/(.*?比)/)){
                        return '<table style="width: 120px">' +
                            '<tr><td style="padding:0;">'+this.series.name+':</td>' +
                            ' <td style="text-align: right"><b style="padding:0;">'+ Highcharts.numberFormat(this.y,0,".",",") +'%</b></td></tr></table>';}
                    //
                    // return '<span style="color: '+ this.series.color + '"></span> '+
                    //     this.series.name+': <b>'+ Highcharts.numberFormat(this.y,0,".",",") +'%</b><br/>';}
                    else {
                        return '<table style="width: 120px">' +
                            '<tr><td style="padding:0;">'+this.series.name+':</td>' +
                            ' <td style="text-align: right"><b style="padding:0;">'+ Highcharts.numberFormat(this.y,0,".",",") +'%</b></td></tr></table>';

                        // return '<span style="color: '+ this.series.color + '"></span> '+
                        //     this.series.name+': <b>'+ Highcharts.numberFormat(this.y,0,".",",")+'</b><br/>';
                    }
                }
            },
            credits:{
                enabled:false
            },
            legend: {
                align: 'center',
                verticalAlign: 'top',
                y: -10,
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
            },
            exporting: {
                chartOptions: {
                    plotOptions: {
                        series: {
                            dataLabels: {
                                enabled: true
                            }
                        }
                    }
                }
            },
            series:this.setSeries(json)
        };
        Highcharts.setOptions({
            lang: {printChart:"打印图表",
                downloadJPEG: "下载JPEG 图片" ,
                downloadPDF: "下载PDF文档"  ,
                downloadPNG: "下载PNG 图片"  ,
                downloadSVG: "下载SVG 矢量图" ,
                exportButtonTitle: "导出图片"
            }
        });
        Highcharts.chart(container,option);
    };
}
